<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>MySQL 存储过程 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../w3cnote/mysql-stored-procedure.html" />
<meta name="keywords" content="MySQL 存储过程">
<meta name="description" content="MySQL 5.0 版本开始支持存储过程。 存储过程（Stored Procedure）是一种在数据库中存储复杂程序，以便外部程序调用的一种数据库对象。 存储过程是为了完成特定功能的SQL语句集，经编译创建并保存在数据库中，用户可通过指定存储过程的名字并给定参数(需要时)来调用执行。 存储过程思想上很简单，就是数据库 SQL 语言层面的代码封装与重用。   优点   存储过程可封装，并隐藏复杂的商业逻辑。 存储过程可以回传值，并可以接受..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<div class="container navigation">
    <div class="row">
        <div class="col nav">
            

                        <ul class="pc-nav" id="note-nav">
                <li><a href="../">首页</a></li>
                <li><a href="../w3cnote">笔记首页</a></li>
                <li><a href="../w3cnote/android-tutorial-intro.html" title="Android 基础入门教程">Android</a></li>
                <li><a href="../w3cnote/es6-tutorial.html" title="ES6 教程">ES6 教程</a></li>
                <li><a href="../w3cnote/ten-sorting-algorithm.html" title="排序算法">排序算法</a></li>
                <li><a href="../w3cnote/hadoop-tutorial.html" title="Hadoop 教程">Hadoop</a></li>
                <li><a href="../w3cnote/zookeeper-tutorial.html" title="Zookeeper 教程">Zookeeper</a></li>
                <li><a href="../w3cnote/verilog-tutorial.html" title="Verilog 教程">Verilog</a></li>
                <li><a href="../w3cnote_genre/code" title="编程技术">编程技术</a></li> 
                <li><a href="../w3cnote_genre/coderlife" title="程序员人生">程序员人生</a></li>
                
                <!--<li><a href="javascript:;" class="runoob-pop">登录</a></li>
                
                
                        <li>
                <a style="font-weight:bold;" href="../linux/linux-tutorial.html#yunserver" target="_blank" onclick="_hmt.push(['_trackEvent', 'aliyun', 'click', 'aliyun'])" title="kkb">云服务器</a>
                </li>
                <li><a href="http://gk.link/a/104mQ" target="_blank" style="font-weight: bold;"onclick="_hmt.push(['_trackEvent', '极客时间', 'click', 'jike'])" title="我的圈子">极客时间</a></li>
            
                
                <li><a target="_blank" href="../shoppinglist" rel="nofollow">知识店铺</a></li> 
        -->
            </ul>
                        
              
            <ul class="mobile-nav">
                <li><a href="../w3cnote">首页</a></li>
                <li><a href="../w3cnote_genre/android" target="_blank" title="Android 基础入门教程">Android</a></li>
                <li><a href="../w3cnote/es6-tutorial.html" target="_blank" title="ES6 教程">ES6</a></li>
                <li><a href="../w3cnote_genre/joke" target="_blank" title="程序员笑话">逗乐</a></li>
                
                <a href="javascript:void(0)" class="search-reveal">Search</a> 
            </ul>
            
        </div>
    </div>
</div>


<!--  内容  -->
<div class="container main">
	<div class="row">

		<div class="col middle-column big-middle-column">
	 			<div class="article">
			<div class="article-heading">
				<h2>MySQL 存储过程</h2>				<h3><em>分类</em> <a href="../w3cnote_genre/code" title="编程技术" >编程技术</a> </h3>
			</div>
			<div class="article-body note-body">
				<div class="article-intro">
					<p>MySQL 5.0 版本开始支持存储过程。</p><p>
存储过程（Stored Procedure）是一种在数据库中存储复杂程序，以便外部程序调用的一种数据库对象。</p><p>
存储过程是为了完成特定功能的SQL语句集，经编译创建并保存在数据库中，用户可通过指定存储过程的名字并给定参数(需要时)来调用执行。</p><p>
存储过程思想上很简单，就是数据库 SQL 语言层面的代码封装与重用。
</p><p>
<h3>
优点
</h3>
<ul><li>
存储过程可封装，并隐藏复杂的商业逻辑。</li><li>
存储过程可以回传值，并可以接受参数。</li><li>
存储过程无法使用 SELECT 指令来运行，因为它是子程序，与查看表，数据表或用户定义函数不同。</li><li>
存储过程可以用在数据检验，强制实行商业逻辑等。</li></ul>
<h3>
缺点</h3>
<ul><li>
存储过程，往往定制化于特定的数据库上，因为支持的编程语言不同。当切换到其他厂商的数据库系统时，需要重写原有的存储过程。</li><li>
存储过程的性能调校与撰写，受限于各种数据库系统。</li></ul>

<h2>一、存储过程的创建和调用</h2>
<ul><li>
存储过程就是具有名字的一段代码，用来完成一个特定的功能。
</li><li>
创建的存储过程保存在数据库的数据字典中。</li></ul>
<h3>创建存储过程</h3>

<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">CREATE</span><span class="hl-code">
    [</span><span class="hl-var">DEFINER</span><span class="hl-code"> = { </span><span class="hl-reserved">user</span><span class="hl-code"> | </span><span class="hl-reserved">CURRENT_USER</span><span class="hl-code"> }]
　</span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">sp_name</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-code">[</span><span class="hl-identifier">proc_parameter</span><span class="hl-code">[,...]]</span><span class="hl-brackets">)</span><span class="hl-code">
    [</span><span class="hl-identifier">characteristic</span><span class="hl-code"> ...] </span><span class="hl-identifier">routine_body</span><span class="hl-code">
 
</span><span class="hl-identifier">proc_parameter</span><span class="hl-code">:
    [ </span><span class="hl-reserved">IN</span><span class="hl-code"> | </span><span class="hl-reserved">OUT</span><span class="hl-code"> | </span><span class="hl-reserved">INOUT</span><span class="hl-code"> ] </span><span class="hl-identifier">param_name</span><span class="hl-code"> </span><span class="hl-var">type</span><span class="hl-code">
 
</span><span class="hl-identifier">characteristic</span><span class="hl-code">:
    </span><span class="hl-identifier">COMMENT</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">string</span><span class="hl-quotes">'</span><span class="hl-code">
  | </span><span class="hl-reserved">LANGUAGE</span><span class="hl-code"> </span><span class="hl-reserved">SQL</span><span class="hl-code">
  | [</span><span class="hl-reserved">NOT</span><span class="hl-code">] </span><span class="hl-reserved">DETERMINISTIC</span><span class="hl-code">
  | { </span><span class="hl-var">CONTAINS</span><span class="hl-code"> </span><span class="hl-reserved">SQL</span><span class="hl-code"> | </span><span class="hl-reserved">NO</span><span class="hl-code"> </span><span class="hl-reserved">SQL</span><span class="hl-code"> | </span><span class="hl-reserved">READS</span><span class="hl-code"> </span><span class="hl-reserved">SQL</span><span class="hl-code"> </span><span class="hl-reserved">DATA</span><span class="hl-code"> | </span><span class="hl-reserved">MODIFIES</span><span class="hl-code"> </span><span class="hl-reserved">SQL</span><span class="hl-code"> </span><span class="hl-reserved">DATA</span><span class="hl-code"> }
  | </span><span class="hl-reserved">SQL</span><span class="hl-code"> </span><span class="hl-var">SECURITY</span><span class="hl-code"> { </span><span class="hl-var">DEFINER</span><span class="hl-code"> | </span><span class="hl-var">INVOKER</span><span class="hl-code"> }
 
</span><span class="hl-identifier">routine_body</span><span class="hl-code">:
　　</span><span class="hl-identifier">Valid</span><span class="hl-code"> </span><span class="hl-reserved">SQL</span><span class="hl-code"> </span><span class="hl-reserved">routine</span><span class="hl-code"> </span><span class="hl-reserved">statement</span><span class="hl-code">
 
[</span><span class="hl-identifier">begin_label</span><span class="hl-code">:] </span><span class="hl-reserved">BEGIN</span><span class="hl-code">
　　[</span><span class="hl-identifier">statement_list</span><span class="hl-code">]
　　　　……
</span><span class="hl-reserved">END</span><span class="hl-code"> [</span><span class="hl-identifier">end_label</span><span class="hl-code">]</span></div>
</div>
</div>


<p><strong>MYSQL 存储过程中的关键语法</strong></p>
<p>声明语句结束符，可以自定义:</p>
<pre>DELIMITER $$
或
DELIMITER //</pre>

<p>声明存储过程:</p>
<pre>CREATE PROCEDURE demo_in_parameter(IN p_in int)       </pre>

<p>存储过程开始和结束符号:</p>
<pre>BEGIN .... END    </pre>

<p>变量赋值:</p>
<pre>SET @p_in=1  </pre>

<p>变量定义:</p>
<pre>DECLARE l_int int unsigned default 4000000; </pre>


<p>创建mysql存储过程、存储函数:</p>
<pre>create procedure 存储过程名(参数)</pre>
<p>存储过程体:</p>
<pre>create function 存储函数名(参数)</pre>
<h3>实例</h3>

<p>创建数据库，备份数据表用于示例操作：</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">create</span><span class="hl-code"> </span><span class="hl-identifier">database</span><span class="hl-code"> </span><span class="hl-identifier">db1</span><span class="hl-code">;
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-identifier">use</span><span class="hl-code"> </span><span class="hl-identifier">db1</span><span class="hl-code">;    
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">create</span><span class="hl-code"> </span><span class="hl-reserved">table</span><span class="hl-code"> </span><span class="hl-identifier">PLAYERS</span><span class="hl-code"> </span><span class="hl-reserved">as</span><span class="hl-code"> </span><span class="hl-reserved">select</span><span class="hl-code"> * </span><span class="hl-reserved">from</span><span class="hl-code"> </span><span class="hl-identifier">TENNIS</span><span class="hl-code">.</span><span class="hl-identifier">PLAYERS</span><span class="hl-code">;
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">create</span><span class="hl-code"> </span><span class="hl-reserved">table</span><span class="hl-code"> </span><span class="hl-identifier">MATCHES</span><span class="hl-code">  </span><span class="hl-reserved">as</span><span class="hl-code"> </span><span class="hl-reserved">select</span><span class="hl-code"> * </span><span class="hl-reserved">from</span><span class="hl-code"> </span><span class="hl-identifier">TENNIS</span><span class="hl-code">.</span><span class="hl-identifier">MATCHES</span><span class="hl-code">;</span></div>
</div>
</div>


<p>下面是存储过程的例子，删除给定球员参加的所有比赛：</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-identifier">delimiter</span><span class="hl-code"> $$　　</span><span class="hl-comment">#将语句的结束符号从分号;临时改为两个$$(可以是自定义)</span><span class="hl-code">
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">delete_matches</span><span class="hl-brackets">(</span><span class="hl-reserved">IN</span><span class="hl-code"> </span><span class="hl-identifier">p_playerno</span><span class="hl-code"> </span><span class="hl-reserved">INTEGER</span><span class="hl-brackets">)</span><span class="hl-code">
    -&gt; </span><span class="hl-reserved">BEGIN</span><span class="hl-code">
    -&gt; 　　</span><span class="hl-reserved">DELETE</span><span class="hl-code"> </span><span class="hl-reserved">FROM</span><span class="hl-code"> </span><span class="hl-identifier">MATCHES</span><span class="hl-code">
    -&gt;    </span><span class="hl-reserved">WHERE</span><span class="hl-code"> </span><span class="hl-identifier">playerno</span><span class="hl-code"> = </span><span class="hl-identifier">p_playerno</span><span class="hl-code">;
    -&gt; </span><span class="hl-reserved">END</span><span class="hl-code">$$
</span><span class="hl-identifier">Query</span><span class="hl-code"> </span><span class="hl-identifier">OK</span><span class="hl-code">, </span><span class="hl-number">0</span><span class="hl-code"> </span><span class="hl-reserved">rows</span><span class="hl-code"> </span><span class="hl-identifier">affected</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-number">0.01</span><span class="hl-code"> </span><span class="hl-identifier">sec</span><span class="hl-brackets">)</span><span class="hl-code">
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-identifier">delimiter</span><span class="hl-code">;　　</span><span class="hl-comment">#将语句的结束符号恢复为分号</span></div>
</div>
</div>



<p><strong>解析：</strong>默认情况下，存储过程和默认数据库相关联，如果想指定存储过程创建在某个特定的数据库下，那么在过程名前面加数据库名做前缀。

在定义过程时，使用 <span class="marked">DELIMITER $$</span> 命令将语句的结束符号从分号 <span class="marked">;</span> 临时改为两个 <span class="marked">$$</span>，使得过程体中使用的分号被直接传递到服务器，而不会被客户端（如mysql）解释。</p>


<p>调用存储过程：</p><pre>call sp_name[(传参)];</pre>

<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">select</span><span class="hl-code"> * </span><span class="hl-reserved">from</span><span class="hl-code"> </span><span class="hl-identifier">MATCHES</span><span class="hl-code">;
+---------+--------+----------+-----+------+
| </span><span class="hl-identifier">MATCHNO</span><span class="hl-code"> | </span><span class="hl-identifier">TEAMNO</span><span class="hl-code"> | </span><span class="hl-identifier">PLAYERNO</span><span class="hl-code"> | </span><span class="hl-identifier">WON</span><span class="hl-code"> | </span><span class="hl-identifier">LOST</span><span class="hl-code"> |
+---------+--------+----------+-----+------+
|       </span><span class="hl-number">1</span><span class="hl-code"> |      </span><span class="hl-number">1</span><span class="hl-code"> |        </span><span class="hl-number">6</span><span class="hl-code"> |   </span><span class="hl-number">3</span><span class="hl-code"> |    </span><span class="hl-number">1</span><span class="hl-code"> |
|       </span><span class="hl-number">7</span><span class="hl-code"> |      </span><span class="hl-number">1</span><span class="hl-code"> |       </span><span class="hl-number">57</span><span class="hl-code"> |   </span><span class="hl-number">3</span><span class="hl-code"> |    </span><span class="hl-number">0</span><span class="hl-code"> |
|       </span><span class="hl-number">8</span><span class="hl-code"> |      </span><span class="hl-number">1</span><span class="hl-code"> |        </span><span class="hl-number">8</span><span class="hl-code"> |   </span><span class="hl-number">0</span><span class="hl-code"> |    </span><span class="hl-number">3</span><span class="hl-code"> |
|       </span><span class="hl-number">9</span><span class="hl-code"> |      </span><span class="hl-number">2</span><span class="hl-code"> |       </span><span class="hl-number">27</span><span class="hl-code"> |   </span><span class="hl-number">3</span><span class="hl-code"> |    </span><span class="hl-number">2</span><span class="hl-code"> |
|      </span><span class="hl-number">11</span><span class="hl-code"> |      </span><span class="hl-number">2</span><span class="hl-code"> |      </span><span class="hl-number">112</span><span class="hl-code"> |   </span><span class="hl-number">2</span><span class="hl-code"> |    </span><span class="hl-number">3</span><span class="hl-code"> |
+---------+--------+----------+-----+------+
</span><span class="hl-number">5</span><span class="hl-code"> </span><span class="hl-reserved">rows</span><span class="hl-code"> </span><span class="hl-reserved">in</span><span class="hl-code"> </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-number">0.00</span><span class="hl-code"> </span><span class="hl-identifier">sec</span><span class="hl-brackets">)</span><span class="hl-code">
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">call</span><span class="hl-code"> </span><span class="hl-identifier">delete_matches</span><span class="hl-brackets">(</span><span class="hl-number">57</span><span class="hl-brackets">)</span><span class="hl-code">;
</span><span class="hl-identifier">Query</span><span class="hl-code"> </span><span class="hl-identifier">OK</span><span class="hl-code">, </span><span class="hl-number">1</span><span class="hl-code"> </span><span class="hl-reserved">row</span><span class="hl-code"> </span><span class="hl-identifier">affected</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-number">0.03</span><span class="hl-code"> </span><span class="hl-identifier">sec</span><span class="hl-brackets">)</span><span class="hl-code">
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">select</span><span class="hl-code"> * </span><span class="hl-reserved">from</span><span class="hl-code"> </span><span class="hl-identifier">MATCHES</span><span class="hl-code">;
+---------+--------+----------+-----+------+
| </span><span class="hl-identifier">MATCHNO</span><span class="hl-code"> | </span><span class="hl-identifier">TEAMNO</span><span class="hl-code"> | </span><span class="hl-identifier">PLAYERNO</span><span class="hl-code"> | </span><span class="hl-identifier">WON</span><span class="hl-code"> | </span><span class="hl-identifier">LOST</span><span class="hl-code"> |
+---------+--------+----------+-----+------+
|       </span><span class="hl-number">1</span><span class="hl-code"> |      </span><span class="hl-number">1</span><span class="hl-code"> |        </span><span class="hl-number">6</span><span class="hl-code"> |   </span><span class="hl-number">3</span><span class="hl-code"> |    </span><span class="hl-number">1</span><span class="hl-code"> |
|       </span><span class="hl-number">8</span><span class="hl-code"> |      </span><span class="hl-number">1</span><span class="hl-code"> |        </span><span class="hl-number">8</span><span class="hl-code"> |   </span><span class="hl-number">0</span><span class="hl-code"> |    </span><span class="hl-number">3</span><span class="hl-code"> |
|       </span><span class="hl-number">9</span><span class="hl-code"> |      </span><span class="hl-number">2</span><span class="hl-code"> |       </span><span class="hl-number">27</span><span class="hl-code"> |   </span><span class="hl-number">3</span><span class="hl-code"> |    </span><span class="hl-number">2</span><span class="hl-code"> |
|      </span><span class="hl-number">11</span><span class="hl-code"> |      </span><span class="hl-number">2</span><span class="hl-code"> |      </span><span class="hl-number">112</span><span class="hl-code"> |   </span><span class="hl-number">2</span><span class="hl-code"> |    </span><span class="hl-number">3</span><span class="hl-code"> |
+---------+--------+----------+-----+------+
</span><span class="hl-number">4</span><span class="hl-code"> </span><span class="hl-reserved">rows</span><span class="hl-code"> </span><span class="hl-reserved">in</span><span class="hl-code"> </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-number">0.00</span><span class="hl-code"> </span><span class="hl-identifier">sec</span><span class="hl-brackets">)</span></div>
</div>
</div>
<p><strong>解析：</strong>在存储过程中设置了需要传参的变量p_playerno，调用存储过程的时候，通过传参将57赋值给p_playerno，然后进行存储过程里的SQL操作。</p>

<p><strong>存储过程体</strong></p>
<ul><li>
存储过程体包含了在过程调用时必须执行的语句，例如：dml、ddl语句，if-then-else和while-do语句、声明变量的declare语句等
</li>
<li>过程体格式：以begin开始，以end结束(可嵌套)</li></ul>


<pre>BEGIN
　　BEGIN
　　　　BEGIN
　　　　　　statements; 
　　　　END
　　END
END</pre>

<p><strong>注意：</strong>每个嵌套块及其中的每条语句，必须以分号结束，表示过程体结束的begin-end块(又叫做复合语句compound statement)，则不需要分号。</p>


<p>为语句块贴标签:</p>

<pre>[begin_label:] BEGIN
　　[statement_list]
END [end_label]</pre>

<p>例如：</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">label1</span><span class="hl-code">: </span><span class="hl-reserved">BEGIN</span><span class="hl-code">
　　</span><span class="hl-identifier">label2</span><span class="hl-code">: </span><span class="hl-reserved">BEGIN</span><span class="hl-code">
　　　　</span><span class="hl-identifier">label3</span><span class="hl-code">: </span><span class="hl-reserved">BEGIN</span><span class="hl-code">
　　　　　　</span><span class="hl-identifier">statements</span><span class="hl-code">; 
　　　　</span><span class="hl-reserved">END</span><span class="hl-code"> </span><span class="hl-identifier">label3</span><span class="hl-code"> ;
　　</span><span class="hl-reserved">END</span><span class="hl-code"> </span><span class="hl-identifier">label2</span><span class="hl-code">;
</span><span class="hl-reserved">END</span><span class="hl-code"> </span><span class="hl-identifier">label1</span></div>
</div>
</div>
<p>标签有两个作用：</p>
<ul><li>
1、增强代码的可读性
</li>
<li>2、在某些语句(例如:leave和iterate语句)，需要用到标签</li></ul>


<h2>二、存储过程的参数</h2>


<p>MySQL存储过程的参数用在存储过程的定义，共有三种参数类型,IN,OUT,INOUT,形式如：</p>
<pre>CREATEPROCEDURE 存储过程名([[IN |OUT |INOUT ] 参数名 数据类形...])</pre>

<ul><li>
IN 输入参数：表示调用者向过程传入值（传入值可以是字面量或变量）
</li>
<li>
OUT 输出参数：表示过程向调用者传出值(可以返回多个值)（传出值只能是变量）
</li>
<li>
INOUT 输入输出参数：既表示调用者向过程传入值，又表示过程向调用者传出值（值只能是变量）</li>
</ul>

<h3>1、in 输入参数</h3>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-identifier">delimiter</span><span class="hl-code"> $$
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">create</span><span class="hl-code"> </span><span class="hl-reserved">procedure</span><span class="hl-code"> </span><span class="hl-identifier">in_param</span><span class="hl-brackets">(</span><span class="hl-reserved">in</span><span class="hl-code"> </span><span class="hl-identifier">p_in</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-brackets">)</span><span class="hl-code">
    -&gt; </span><span class="hl-reserved">begin</span><span class="hl-code">
    -&gt; 　　</span><span class="hl-reserved">select</span><span class="hl-code"> </span><span class="hl-identifier">p_in</span><span class="hl-code">;
    -&gt; 　　</span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">p_in</span><span class="hl-code">=</span><span class="hl-number">2</span><span class="hl-code">;
    -&gt;    </span><span class="hl-reserved">select</span><span class="hl-code"> </span><span class="hl-identifier">P_in</span><span class="hl-code">;
    -&gt; </span><span class="hl-reserved">end</span><span class="hl-code">$$
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-identifier">delimiter</span><span class="hl-code"> ;
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> @</span><span class="hl-identifier">p_in</span><span class="hl-code">=</span><span class="hl-number">1</span><span class="hl-code">;
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">call</span><span class="hl-code"> </span><span class="hl-identifier">in_param</span><span class="hl-brackets">(</span><span class="hl-code">@</span><span class="hl-identifier">p_in</span><span class="hl-brackets">)</span><span class="hl-code">;
+------+
| </span><span class="hl-identifier">p_in</span><span class="hl-code"> |
+------+
|    </span><span class="hl-number">1</span><span class="hl-code"> |
+------+
 
+------+
| </span><span class="hl-identifier">P_in</span><span class="hl-code"> |
+------+
|    </span><span class="hl-number">2</span><span class="hl-code"> |
+------+
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">select</span><span class="hl-code"> @</span><span class="hl-identifier">p_in</span><span class="hl-code">;
+-------+
| @</span><span class="hl-identifier">p_in</span><span class="hl-code"> |
+-------+
|     </span><span class="hl-number">1</span><span class="hl-code"> |
+-------+</span></div>
</div>
</div>
<p>以上可以看出，p_in 在存储过程中被修改，但并不影响 <strong>@p_in</strong> 的值，因为前者为局部变量、后者为全局变量。</p>

<h3>2、out输出参数</h3>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-identifier">delimiter</span><span class="hl-code"> //
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">create</span><span class="hl-code"> </span><span class="hl-reserved">procedure</span><span class="hl-code"> </span><span class="hl-identifier">out_param</span><span class="hl-brackets">(</span><span class="hl-reserved">out</span><span class="hl-code"> </span><span class="hl-identifier">p_out</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-brackets">)</span><span class="hl-code">
    -&gt;   </span><span class="hl-reserved">begin</span><span class="hl-code">
    -&gt;     </span><span class="hl-reserved">select</span><span class="hl-code"> </span><span class="hl-identifier">p_out</span><span class="hl-code">;
    -&gt;     </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">p_out</span><span class="hl-code">=</span><span class="hl-number">2</span><span class="hl-code">;
    -&gt;     </span><span class="hl-reserved">select</span><span class="hl-code"> </span><span class="hl-identifier">p_out</span><span class="hl-code">;
    -&gt;   </span><span class="hl-reserved">end</span><span class="hl-code">
    -&gt; //
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-identifier">delimiter</span><span class="hl-code"> ;
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> @</span><span class="hl-identifier">p_out</span><span class="hl-code">=</span><span class="hl-number">1</span><span class="hl-code">;
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">call</span><span class="hl-code"> </span><span class="hl-identifier">out_param</span><span class="hl-brackets">(</span><span class="hl-code">@</span><span class="hl-identifier">p_out</span><span class="hl-brackets">)</span><span class="hl-code">;
+-------+
| </span><span class="hl-identifier">p_out</span><span class="hl-code"> |
+-------+
|  </span><span class="hl-reserved">NULL</span><span class="hl-code"> |
+-------+
　　</span><span class="hl-comment">#因为out是向调用者输出参数，不接收输入的参数，所以存储过程里的p_out为null</span><span class="hl-code">
+-------+
| </span><span class="hl-identifier">p_out</span><span class="hl-code"> |
+-------+
|     </span><span class="hl-number">2</span><span class="hl-code"> |
+-------+
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">select</span><span class="hl-code"> @</span><span class="hl-identifier">p_out</span><span class="hl-code">;
+--------+
| @</span><span class="hl-identifier">p_out</span><span class="hl-code"> |
+--------+
|      </span><span class="hl-number">2</span><span class="hl-code"> |
+--------+
　　</span><span class="hl-comment">#调用了out_param存储过程，输出参数，改变了p_out变量的值</span></div>
</div>
</div>
<h3>3、inout输入参数</h3>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-identifier">delimiter</span><span class="hl-code"> $$
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">create</span><span class="hl-code"> </span><span class="hl-reserved">procedure</span><span class="hl-code"> </span><span class="hl-identifier">inout_param</span><span class="hl-brackets">(</span><span class="hl-reserved">inout</span><span class="hl-code"> </span><span class="hl-identifier">p_inout</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-brackets">)</span><span class="hl-code">
    -&gt;   </span><span class="hl-reserved">begin</span><span class="hl-code">
    -&gt;     </span><span class="hl-reserved">select</span><span class="hl-code"> </span><span class="hl-identifier">p_inout</span><span class="hl-code">;
    -&gt;     </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">p_inout</span><span class="hl-code">=</span><span class="hl-number">2</span><span class="hl-code">;
    -&gt;     </span><span class="hl-reserved">select</span><span class="hl-code"> </span><span class="hl-identifier">p_inout</span><span class="hl-code">;
    -&gt;   </span><span class="hl-reserved">end</span><span class="hl-code">
    -&gt; $$
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-identifier">delimiter</span><span class="hl-code"> ;
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> @</span><span class="hl-identifier">p_inout</span><span class="hl-code">=</span><span class="hl-number">1</span><span class="hl-code">;
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">call</span><span class="hl-code"> </span><span class="hl-identifier">inout_param</span><span class="hl-brackets">(</span><span class="hl-code">@</span><span class="hl-identifier">p_inout</span><span class="hl-brackets">)</span><span class="hl-code">;
+---------+
| </span><span class="hl-identifier">p_inout</span><span class="hl-code"> |
+---------+
|       </span><span class="hl-number">1</span><span class="hl-code"> |
+---------+
 
+---------+
| </span><span class="hl-identifier">p_inout</span><span class="hl-code"> |
+---------+
|       </span><span class="hl-number">2</span><span class="hl-code"> |
+---------+
 
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">select</span><span class="hl-code"> @</span><span class="hl-identifier">p_inout</span><span class="hl-code">;
+----------+
| @</span><span class="hl-identifier">p_inout</span><span class="hl-code"> |
+----------+
|        </span><span class="hl-number">2</span><span class="hl-code"> |
+----------+
</span><span class="hl-comment">#调用了inout_param存储过程，接受了输入的参数，也输出参数，改变了变量</span></div>
</div>
</div>

<p><strong>注意：</strong></p>

<p>1、如果过程没有参数，也必须在过程名后面写上小括号例：</p>
<pre>CREATE PROCEDURE sp_name ([proc_parameter[,...]]) &hellip;&hellip;</pre>

<p>2、确保参数的名字不等于列的名字，否则在过程体中，参数名被当做列名来处理</p>

<p><strong>建议：</strong></p>
<ul><li>
输入值使用in参数。
</li><li>返回值使用out参数。
</li><li>inout参数就尽量的少用。</li></ul>
<hr><h2>
三、变量</h2><h3>
1. 变量定义</h3>
<p>局部变量声明一定要放在存储过程体的开始：</p>
<pre>DECLAREvariable_name [,variable_name...] datatype [DEFAULT value];</pre>
<p>其中，datatype 为 MySQL 的数据类型，如: int, float, date,varchar(length)</p>
<p>例如:</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">DECLARE</span><span class="hl-code"> </span><span class="hl-identifier">l_int</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-code"> </span><span class="hl-identifier">unsigned</span><span class="hl-code"> </span><span class="hl-reserved">default</span><span class="hl-code"> </span><span class="hl-number">4000000</span><span class="hl-code">;  
</span><span class="hl-reserved">DECLARE</span><span class="hl-code"> </span><span class="hl-identifier">l_numeric</span><span class="hl-code"> </span><span class="hl-var">number</span><span class="hl-brackets">(</span><span class="hl-number">8</span><span class="hl-code">,</span><span class="hl-number">2</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">DEFAULT</span><span class="hl-code"> </span><span class="hl-number">9.95</span><span class="hl-code">;  
</span><span class="hl-reserved">DECLARE</span><span class="hl-code"> </span><span class="hl-identifier">l_date</span><span class="hl-code"> </span><span class="hl-reserved">date</span><span class="hl-code"> </span><span class="hl-reserved">DEFAULT</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">1999-12-31</span><span class="hl-quotes">'</span><span class="hl-code">;  
</span><span class="hl-reserved">DECLARE</span><span class="hl-code"> </span><span class="hl-identifier">l_datetime</span><span class="hl-code"> </span><span class="hl-identifier">datetime</span><span class="hl-code"> </span><span class="hl-reserved">DEFAULT</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">1999-12-31 23:59:59</span><span class="hl-quotes">'</span><span class="hl-code">;  
</span><span class="hl-reserved">DECLARE</span><span class="hl-code"> </span><span class="hl-identifier">l_varchar</span><span class="hl-code"> </span><span class="hl-reserved">varchar</span><span class="hl-brackets">(</span><span class="hl-number">255</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">DEFAULT</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">This will not be padded</span><span class="hl-quotes">'</span><span class="hl-code">;</span></div>
</div>
</div><h3>
2. 变量赋值</h3><pre>
SET 变量名 = 表达式值 [,variable_name = expression ...]</pre>
<h3>
3. 用户变量
</h3>
<p>在MySQL客户端使用用户变量:</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">SELECT</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">Hello World</span><span class="hl-quotes">'</span><span class="hl-code"> </span><span class="hl-reserved">into</span><span class="hl-code"> @</span><span class="hl-identifier">x</span><span class="hl-code">;  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">SELECT</span><span class="hl-code"> @</span><span class="hl-identifier">x</span><span class="hl-code">;  
+-------------+  
|   @</span><span class="hl-identifier">x</span><span class="hl-code">        |  
+-------------+  
| </span><span class="hl-identifier">Hello</span><span class="hl-code"> </span><span class="hl-identifier">World</span><span class="hl-code"> |  
+-------------+  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">SET</span><span class="hl-code"> @</span><span class="hl-identifier">y</span><span class="hl-code">=</span><span class="hl-quotes">'</span><span class="hl-string">Goodbye Cruel World</span><span class="hl-quotes">'</span><span class="hl-code">;  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">SELECT</span><span class="hl-code"> @</span><span class="hl-identifier">y</span><span class="hl-code">;  
+---------------------+  
|     @</span><span class="hl-identifier">y</span><span class="hl-code">              |  
+---------------------+  
| </span><span class="hl-identifier">Goodbye</span><span class="hl-code"> </span><span class="hl-identifier">Cruel</span><span class="hl-code"> </span><span class="hl-identifier">World</span><span class="hl-code"> |  
+---------------------+  
 
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">SET</span><span class="hl-code"> @</span><span class="hl-identifier">z</span><span class="hl-code">=</span><span class="hl-number">1</span><span class="hl-code">+</span><span class="hl-number">2</span><span class="hl-code">+</span><span class="hl-number">3</span><span class="hl-code">;  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">SELECT</span><span class="hl-code"> @</span><span class="hl-identifier">z</span><span class="hl-code">;  
+------+  
| @</span><span class="hl-identifier">z</span><span class="hl-code">   |  
+------+  
|  </span><span class="hl-number">6</span><span class="hl-code">   |  
+------+</span></div>
</div>
</div>
<p><strong>在存储过程中使用用户变量</strong></p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">GreetWorld</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">SELECT</span><span class="hl-code"> </span><span class="hl-identifier">CONCAT</span><span class="hl-brackets">(</span><span class="hl-code">@</span><span class="hl-identifier">greeting</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string"> World</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">SET</span><span class="hl-code"> @</span><span class="hl-identifier">greeting</span><span class="hl-code">=</span><span class="hl-quotes">'</span><span class="hl-string">Hello</span><span class="hl-quotes">'</span><span class="hl-code">;  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">CALL</span><span class="hl-code"> </span><span class="hl-identifier">GreetWorld</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;  
+----------------------------+  
| </span><span class="hl-identifier">CONCAT</span><span class="hl-brackets">(</span><span class="hl-code">@</span><span class="hl-identifier">greeting</span><span class="hl-code">,</span><span class="hl-quotes">'</span><span class="hl-string"> World</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code"> |  
+----------------------------+  
|  </span><span class="hl-identifier">Hello</span><span class="hl-code"> </span><span class="hl-identifier">World</span><span class="hl-code">               |  
+----------------------------+</span></div>
</div>
</div>
<p><strong>在存储过程间传递全局范围的用户变量</strong></p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">p1</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">   </span><span class="hl-reserved">SET</span><span class="hl-code"> @</span><span class="hl-identifier">last_procedure</span><span class="hl-code">=</span><span class="hl-quotes">'</span><span class="hl-string">p1</span><span class="hl-quotes">'</span><span class="hl-code">;  
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">p2</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">SELECT</span><span class="hl-code"> </span><span class="hl-identifier">CONCAT</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">Last procedure was </span><span class="hl-quotes">'</span><span class="hl-code">,@</span><span class="hl-identifier">last_procedure</span><span class="hl-brackets">)</span><span class="hl-code">;  
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">CALL</span><span class="hl-code"> </span><span class="hl-identifier">p1</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;  
</span><span class="hl-identifier">mysql</span><span class="hl-code">&gt; </span><span class="hl-reserved">CALL</span><span class="hl-code"> </span><span class="hl-identifier">p2</span><span class="hl-brackets">(</span><span class="hl-code"> </span><span class="hl-brackets">)</span><span class="hl-code">;  
+-----------------------------------------------+  
| </span><span class="hl-identifier">CONCAT</span><span class="hl-brackets">(</span><span class="hl-quotes">'</span><span class="hl-string">Last procedure was </span><span class="hl-quotes">'</span><span class="hl-code">,@</span><span class="hl-identifier">last_proc</span><span class="hl-code">       |  
+-----------------------------------------------+  
| </span><span class="hl-reserved">Last</span><span class="hl-code"> </span><span class="hl-reserved">procedure</span><span class="hl-code"> </span><span class="hl-identifier">was</span><span class="hl-code"> </span><span class="hl-identifier">p1</span><span class="hl-code">                         |  
 +-----------------------------------------------+</span></div>
</div>
</div>
<p><strong>注意:</strong></p>
<ul><li>
1、用户变量名一般以@开头</li><li>
2、滥用用户变量会导致程序难以理解及管理</li></ul>
<hr>
<h2>四、注释
</h2>
 

<p>MySQL 存储过程可使用两种风格的注释</p>

<p>两个横杆<span class="marked">--</span>：该风格一般用于单行注释。</p>



<p><strong>c 风格</strong>： 一般用于多行注释。</p>

<p>例如：</p>

 
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">proc1</span><span class="hl-code"> --</span><span class="hl-var">name</span><span class="hl-code">存储过程名  
     -&gt; </span><span class="hl-brackets">(</span><span class="hl-reserved">IN</span><span class="hl-code"> </span><span class="hl-identifier">parameter1</span><span class="hl-code"> </span><span class="hl-reserved">INTEGER</span><span class="hl-brackets">)</span><span class="hl-code">   
     -&gt; </span><span class="hl-reserved">BEGIN</span><span class="hl-code">   
     -&gt; </span><span class="hl-reserved">DECLARE</span><span class="hl-code"> </span><span class="hl-identifier">variable1</span><span class="hl-code"> </span><span class="hl-reserved">CHAR</span><span class="hl-brackets">(</span><span class="hl-number">10</span><span class="hl-brackets">)</span><span class="hl-code">;   
     -&gt; </span><span class="hl-identifier">IF</span><span class="hl-code"> </span><span class="hl-identifier">parameter1</span><span class="hl-code"> = </span><span class="hl-number">17</span><span class="hl-code"> </span><span class="hl-reserved">THEN</span><span class="hl-code">   
     -&gt; </span><span class="hl-reserved">SET</span><span class="hl-code"> </span><span class="hl-identifier">variable1</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">birds</span><span class="hl-quotes">'</span><span class="hl-code">;   
     -&gt; </span><span class="hl-reserved">ELSE</span><span class="hl-code"> 
     -&gt; </span><span class="hl-reserved">SET</span><span class="hl-code"> </span><span class="hl-identifier">variable1</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">beasts</span><span class="hl-quotes">'</span><span class="hl-code">;   
    -&gt; </span><span class="hl-reserved">END</span><span class="hl-code"> </span><span class="hl-identifier">IF</span><span class="hl-code">;   
    -&gt; </span><span class="hl-reserved">INSERT</span><span class="hl-code"> </span><span class="hl-reserved">INTO</span><span class="hl-code"> </span><span class="hl-identifier">table1</span><span class="hl-code"> </span><span class="hl-reserved">VALUES</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">variable1</span><span class="hl-brackets">)</span><span class="hl-code">;  
    -&gt; </span><span class="hl-reserved">END</span><span class="hl-code">   
    -&gt; //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> ;</span></div>
</div>
</div>

<h3>MySQL存储过程的调用
</h3>
<p>用call和你过程名以及一个括号，括号里面根据需要，加入参数，参数包括输入参数、输出参数、输入输出参数。具体的调用方法可以参看上面的例子。</p>

<h3>MySQL存储过程的查询</h3>

<p>我们像知道一个数据库下面有那些表，我们一般采用 <span class="marked">showtables;</span> 进行查看。那么我们要查看某个数据库下面的存储过程，是否也可以采用呢？答案是，我们可以查看某个数据库下面的存储过程，但是是另一钟方式。</p>

<p>我们可以用以下语句进行查询：</p>

<pre>selectname from mysql.proc where db='数据库名';

或者

selectroutine_name from information_schema.routines where routine_schema='数据库名';

或者

showprocedure status where db='数据库名';</pre>



<p><strong>如果我们想知道，某个存储过程的详细，那我们又该怎么做呢？是不是也可以像操作表一样用describe 表名进行查看呢？</strong></p>

<p><strong>答案是：</strong>我们可以查看存储过程的详细，但是需要用另一种方法：</p>

<pre>SHOW CREATE PROCEDURE 数据库.存储过程名;</pre>

<p>就可以查看当前存储过程的详细。</p>

 

<h3>MySQL存储过程的修改
</h3>
<pre>ALTER PROCEDURE</pre>
<p>
更改用 CREATE PROCEDURE 建立的预先指定的存储过程，其不会影响相关存储过程或存储功能。</p>

 

<h3>MySQL存储过程的删除</h3>

<p>删除一个存储过程比较简单，和删除表一样：</p>

<pre>DROPPROCEDURE</pre>

<p>从 MySQL 的表格中删除一个或多个存储过程。</p>

 

<h3> MySQL存储过程的控制语句
</h3>
<p><strong>(1). 变量作用域</strong></p>

<p>内部的变量在其作用域范围内享有更高的优先权，当执行到 end。变量时，内部变量消失，此时已经在其作用域外，变量不再可见了，应为在存储过程外再也不能找到这个申明的变量，但是你可以通过 out 参数或者将其值指派给会话变量来保存其值。</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">proc3</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">begin</span><span class="hl-code"> 
     -&gt; </span><span class="hl-reserved">declare</span><span class="hl-code"> </span><span class="hl-identifier">x1</span><span class="hl-code"> </span><span class="hl-reserved">varchar</span><span class="hl-brackets">(</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">default</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">outer</span><span class="hl-quotes">'</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">begin</span><span class="hl-code"> 
     -&gt; </span><span class="hl-reserved">declare</span><span class="hl-code"> </span><span class="hl-identifier">x1</span><span class="hl-code"> </span><span class="hl-reserved">varchar</span><span class="hl-brackets">(</span><span class="hl-number">5</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">default</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">inner</span><span class="hl-quotes">'</span><span class="hl-code">;  
      -&gt; </span><span class="hl-reserved">select</span><span class="hl-code"> </span><span class="hl-identifier">x1</span><span class="hl-code">;  
      -&gt; </span><span class="hl-reserved">end</span><span class="hl-code">;  
       -&gt; </span><span class="hl-reserved">select</span><span class="hl-code"> </span><span class="hl-identifier">x1</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code">;  
     -&gt; //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> ;</span></div>
</div>
</div> 

<p><strong>(2). 条件语句</strong></p>

<p>1. if-then-else 语句 </p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">proc2</span><span class="hl-brackets">(</span><span class="hl-reserved">IN</span><span class="hl-code"> </span><span class="hl-reserved">parameter</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-brackets">)</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">begin</span><span class="hl-code"> 
     -&gt; </span><span class="hl-reserved">declare</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code">=</span><span class="hl-reserved">parameter</span><span class="hl-code">+</span><span class="hl-number">1</span><span class="hl-code">;  
     -&gt; </span><span class="hl-identifier">if</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code"> </span><span class="hl-reserved">then</span><span class="hl-code"> 
     -&gt; </span><span class="hl-reserved">insert</span><span class="hl-code"> </span><span class="hl-reserved">into</span><span class="hl-code"> </span><span class="hl-identifier">t</span><span class="hl-code"> </span><span class="hl-reserved">values</span><span class="hl-brackets">(</span><span class="hl-number">17</span><span class="hl-brackets">)</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code"> </span><span class="hl-identifier">if</span><span class="hl-code">;  
     -&gt; </span><span class="hl-identifier">if</span><span class="hl-code"> </span><span class="hl-reserved">parameter</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code"> </span><span class="hl-reserved">then</span><span class="hl-code"> 
     -&gt; </span><span class="hl-reserved">update</span><span class="hl-code"> </span><span class="hl-identifier">t</span><span class="hl-code"> </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">s1</span><span class="hl-code">=</span><span class="hl-identifier">s1</span><span class="hl-code">+</span><span class="hl-number">1</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">else</span><span class="hl-code"> 
     -&gt; </span><span class="hl-reserved">update</span><span class="hl-code"> </span><span class="hl-identifier">t</span><span class="hl-code"> </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">s1</span><span class="hl-code">=</span><span class="hl-identifier">s1</span><span class="hl-code">+</span><span class="hl-number">2</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code"> </span><span class="hl-identifier">if</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code">;  
     -&gt; //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> ;</span></div>
</div>
</div>
<p>2. case语句：</p> 
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">proc3</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-reserved">in</span><span class="hl-code"> </span><span class="hl-reserved">parameter</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-brackets">)</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">begin</span><span class="hl-code"> 
     -&gt; </span><span class="hl-reserved">declare</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code">=</span><span class="hl-reserved">parameter</span><span class="hl-code">+</span><span class="hl-number">1</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">case</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">when</span><span class="hl-code"> </span><span class="hl-number">0</span><span class="hl-code"> </span><span class="hl-reserved">then</span><span class="hl-code">   
     -&gt; </span><span class="hl-reserved">insert</span><span class="hl-code"> </span><span class="hl-reserved">into</span><span class="hl-code"> </span><span class="hl-identifier">t</span><span class="hl-code"> </span><span class="hl-reserved">values</span><span class="hl-brackets">(</span><span class="hl-number">17</span><span class="hl-brackets">)</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">when</span><span class="hl-code"> </span><span class="hl-number">1</span><span class="hl-code"> </span><span class="hl-reserved">then</span><span class="hl-code">   
     -&gt; </span><span class="hl-reserved">insert</span><span class="hl-code"> </span><span class="hl-reserved">into</span><span class="hl-code"> </span><span class="hl-identifier">t</span><span class="hl-code"> </span><span class="hl-reserved">values</span><span class="hl-brackets">(</span><span class="hl-number">18</span><span class="hl-brackets">)</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">else</span><span class="hl-code">   
     -&gt; </span><span class="hl-reserved">insert</span><span class="hl-code"> </span><span class="hl-reserved">into</span><span class="hl-code"> </span><span class="hl-identifier">t</span><span class="hl-code"> </span><span class="hl-reserved">values</span><span class="hl-brackets">(</span><span class="hl-number">19</span><span class="hl-brackets">)</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code"> </span><span class="hl-reserved">case</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code">;  
     -&gt; //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> ; 
</span><span class="hl-reserved">case</span><span class="hl-code">
    </span><span class="hl-reserved">when</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code"> </span><span class="hl-reserved">then</span><span class="hl-code">
        </span><span class="hl-reserved">insert</span><span class="hl-code"> </span><span class="hl-reserved">into</span><span class="hl-code"> </span><span class="hl-identifier">t</span><span class="hl-code"> </span><span class="hl-reserved">values</span><span class="hl-brackets">(</span><span class="hl-number">30</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-reserved">when</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code">&gt;</span><span class="hl-number">0</span><span class="hl-code"> </span><span class="hl-reserved">then</span><span class="hl-code">
    </span><span class="hl-reserved">when</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code">&lt;</span><span class="hl-number">0</span><span class="hl-code"> </span><span class="hl-reserved">then</span><span class="hl-code">
    </span><span class="hl-reserved">else</span><span class="hl-code">
</span><span class="hl-reserved">end</span><span class="hl-code"> </span><span class="hl-reserved">case</span></div>
</div>
</div> 
 
 

<p><strong>(3). 循环语句</strong></p>

<p>1. while ···· end while</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">proc4</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">begin</span><span class="hl-code"> 
     -&gt; </span><span class="hl-reserved">declare</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">;  
     -&gt; </span><span class="hl-identifier">while</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code">&lt;</span><span class="hl-number">6</span><span class="hl-code"> </span><span class="hl-identifier">do</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">insert</span><span class="hl-code"> </span><span class="hl-reserved">into</span><span class="hl-code"> </span><span class="hl-identifier">t</span><span class="hl-code"> </span><span class="hl-reserved">values</span><span class="hl-brackets">(</span><span class="hl-identifier">var</span><span class="hl-brackets">)</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">var</span><span class="hl-code">=</span><span class="hl-identifier">var</span><span class="hl-code">+</span><span class="hl-number">1</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code"> </span><span class="hl-identifier">while</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code">;  
     -&gt; //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> ;</span></div>
</div>
</div>
<pre>while 条件 do
    --循环体
endwhile</pre>

<p>2. repeat···· end repeat</p>

<p>它在执行操作后检查结果，而 while 则是执行前进行检查。</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">proc5</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">begin</span><span class="hl-code">   
     -&gt; </span><span class="hl-reserved">declare</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">;  
     -&gt; </span><span class="hl-identifier">repeat</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">insert</span><span class="hl-code"> </span><span class="hl-reserved">into</span><span class="hl-code"> </span><span class="hl-identifier">t</span><span class="hl-code"> </span><span class="hl-reserved">values</span><span class="hl-brackets">(</span><span class="hl-identifier">v</span><span class="hl-brackets">)</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code">=</span><span class="hl-identifier">v</span><span class="hl-code">+</span><span class="hl-number">1</span><span class="hl-code">;  
     -&gt; </span><span class="hl-identifier">until</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code">&gt;=</span><span class="hl-number">5</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code"> </span><span class="hl-identifier">repeat</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code">;  
     -&gt; //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> ;</span></div>
</div>
</div>
<pre>repeat
    --循环体
until 循环条件  
end repeat;</pre>

 


<p>3. loop ·····endloop</p>

<p>loop 循环不需要初始条件，这点和 while 循环相似，同时和 repeat 循环一样不需要结束条件, leave 语句的意义是离开循环。</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">proc6</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">begin</span><span class="hl-code"> 
     -&gt; </span><span class="hl-reserved">declare</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">;  
     -&gt; </span><span class="hl-identifier">LOOP_LABLE</span><span class="hl-code">:</span><span class="hl-identifier">loop</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">insert</span><span class="hl-code"> </span><span class="hl-reserved">into</span><span class="hl-code"> </span><span class="hl-identifier">t</span><span class="hl-code"> </span><span class="hl-reserved">values</span><span class="hl-brackets">(</span><span class="hl-identifier">v</span><span class="hl-brackets">)</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code">=</span><span class="hl-identifier">v</span><span class="hl-code">+</span><span class="hl-number">1</span><span class="hl-code">;  
     -&gt; </span><span class="hl-identifier">if</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code"> &gt;=</span><span class="hl-number">5</span><span class="hl-code"> </span><span class="hl-reserved">then</span><span class="hl-code"> 
     -&gt; </span><span class="hl-identifier">leave</span><span class="hl-code"> </span><span class="hl-identifier">LOOP_LABLE</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code"> </span><span class="hl-identifier">if</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code"> </span><span class="hl-identifier">loop</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code">;  
     -&gt; //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> ;</span></div>
</div>
</div> 

 

<p>4. LABLES 标号：</p>

<p>标号可以用在 begin repeat while 或者 loop 语句前，语句标号只能在合法的语句前面使用。可以跳出循环，使运行指令达到复合语句的最后一步。</p>

 

<p><strong>(4). ITERATE迭代</strong></p>

<p>ITERATE 通过引用复合语句的标号,来从新开始复合语句:</p>
<div class="example">
<div class="example_code">
<div class="hl-main"><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-reserved">CREATE</span><span class="hl-code"> </span><span class="hl-reserved">PROCEDURE</span><span class="hl-code"> </span><span class="hl-identifier">proc10</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">  
     -&gt; </span><span class="hl-reserved">begin</span><span class="hl-code"> 
     -&gt; </span><span class="hl-reserved">declare</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code"> </span><span class="hl-reserved">int</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code">=</span><span class="hl-number">0</span><span class="hl-code">;  
     -&gt; </span><span class="hl-identifier">LOOP_LABLE</span><span class="hl-code">:</span><span class="hl-identifier">loop</span><span class="hl-code">  
     -&gt; </span><span class="hl-identifier">if</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code">=</span><span class="hl-number">3</span><span class="hl-code"> </span><span class="hl-reserved">then</span><span class="hl-code">   
     -&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code">=</span><span class="hl-identifier">v</span><span class="hl-code">+</span><span class="hl-number">1</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">ITERATE</span><span class="hl-code"> </span><span class="hl-identifier">LOOP_LABLE</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code"> </span><span class="hl-identifier">if</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">insert</span><span class="hl-code"> </span><span class="hl-reserved">into</span><span class="hl-code"> </span><span class="hl-identifier">t</span><span class="hl-code"> </span><span class="hl-reserved">values</span><span class="hl-brackets">(</span><span class="hl-identifier">v</span><span class="hl-brackets">)</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">set</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code">=</span><span class="hl-identifier">v</span><span class="hl-code">+</span><span class="hl-number">1</span><span class="hl-code">;  
     -&gt; </span><span class="hl-identifier">if</span><span class="hl-code"> </span><span class="hl-identifier">v</span><span class="hl-code">&gt;=</span><span class="hl-number">5</span><span class="hl-code"> </span><span class="hl-reserved">then</span><span class="hl-code"> 
     -&gt; </span><span class="hl-identifier">leave</span><span class="hl-code"> </span><span class="hl-identifier">LOOP_LABLE</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code"> </span><span class="hl-identifier">if</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code"> </span><span class="hl-identifier">loop</span><span class="hl-code">;  
     -&gt; </span><span class="hl-reserved">end</span><span class="hl-code">;  
     -&gt; //  
</span><span class="hl-identifier">mysql</span><span class="hl-code"> &gt; </span><span class="hl-identifier">DELIMITER</span><span class="hl-code"> ;</span></div>
</div>
</div>


<blockquote><p>参考文章：</p>
<p>https://www.cnblogs.com/geaozhang/p/6797357.html</p>
<p>http://blog.sina.com.cn/s/blog_86fe5b440100wdyt.html</p></blockquote>

				</div>
			</div>
			<div class="previous-next-links">
			<div class="previous-design-link">← <a href="../w3cnote/eclipse-shortcuts.html" rel="prev"> Eclipse 常用快捷键及使用技巧</a> </div>
			<div class="next-design-link"><a href="../w3cnote/onreadystatechange-attribute-learn.html" rel="next"> 对 onreadystatechange 属性的理解</a> →</div>
			</div>
			<style>
.wrapper {
  /*text-transform: uppercase; */
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  position: relative;
  text-align: center;
  width: 200px;
  -webkit-transform: translateZ(0); /* webkit flicker fix */
  -webkit-font-smoothing: antialiased; /* webkit text rendering fix */
}

.wrapper .tooltip {
  white-space: nowrap;
  font-size: 14px;
  text-align: left;
  background: #96b97d;
  bottom: 100%;
  color: #fff;
  display: block;
  left: -25px;
  margin-bottom: 15px;
  opacity: 0;
  padding: 14px;
  pointer-events: none;
  position: absolute;
  
  -webkit-transform: translateY(10px);
     -moz-transform: translateY(10px);
      -ms-transform: translateY(10px);
       -o-transform: translateY(10px);
          transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
     -moz-transition: all .25s ease-out;
      -ms-transition: all .25s ease-out;
       -o-transition: all .25s ease-out;
          transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
     -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
      -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
       -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
          box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}
.tooltip a {
	color:#fff;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.wrapper .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}  

/* CSS Triangles - see Trevor's post */
.wrapper .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid #96b97d 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 20%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}
.wrapper .tooltip1 {
	margin-left: 50px;
	padding-top: 0px;
}
/*
.wrapper:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  -webkit-transform: translateY(0px);
     -moz-transform: translateY(0px);
      -ms-transform: translateY(0px);
       -o-transform: translateY(0px);
          transform: translateY(0px);
}
*/
/* IE can just show/hide with no transition */
.lte8 .wrapper .tooltip {
  display: none;
}

.lte8 .wrapper:hover .tooltip {
  display: block;
}

</style>

<link rel="stylesheet" href="../0/upvotejs.css">
<script src=""></script>
<script src=""></script>
<div id="respond" class="no_webshot"> 
		<div class="comment-signarea" style=" padding: 20px 20px;"> 
	<h3 class="text-muted" id="share_code" style="color: #799961;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> 点我分享笔记</h3>
	<!--
	<p style="font-size:14px;">笔记需要是本篇文章的内容扩展！</p><br>
	<p style="font-size:12px;"><a href="../tougao" target="_blank">文章投稿，可点击这里</a></p>
	<p style="font-size:14px;"><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>
		<h3 class="text-muted"><i class="fa fa-info-circle" aria-hidden="true"></i> 分享笔记前必须<a href="javascript:;" class="runoob-pop">登录</a>！</h3>
		<p><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>-->
	</div>
		
	<form action="/wp-content/themes/runoob/option/addnote.php" method="post" id="commentform" style="display:none;">
		<div class="comt">
			<div class="comt-title">
				<i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i>				<p><a id="cancel-comment-reply-link" href="javascript:;">取消</a></p>
			</div>
			<div class="comt-box">
			<div id="mded"></div>
			
				<div class="comt-ctrl">
					<div class="comt-tips"><input type='hidden' name='comment_post_ID' value='20780' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</div>
					<button type="submit" name="submit" id="submit" tabindex="5"><i class="fa fa-pencil" aria-hidden="true"></i> 分享笔记</button>
				</div>
			</div>
		
				
					<div class="comt-comterinfo"> 
						<ul id="comment-author-info">
							<li class="form-inline"><label class="hide" for="author">昵称</label><input class="ipt" type="text" name="author" id="author" value="" tabindex="2" placeholder="昵称"><span class="text-muted">昵称 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="email" id="email" value="" tabindex="3" placeholder="邮箱"><span class="text-muted">邮箱 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="url">引用地址</label><input class="ipt" type="text" name="url" id="url" value="" tabindex="4" placeholder="引用地址"><span class="text-muted">引用地址</span></li>
						</ul>
					</div>
				
			
		</div>

	</form>
	</div>
<script type="text/javascript">
$(function() {
	//初始化编辑器
	
	var editor = new Simditor({
	  textarea: $('#mded'),
	  placeholder: '写笔记...',
	  upload:false,
	 // upload: {url:'/api/comment_upload_file.php',params: null,fileKey: 'upload_file',connectionCount: 1,leaveConfirm: '文件正在上传，您确定离开?'},
	  defaultImage: 'https://www.runoob.com/images/logo.png',
	  codeLanguages: '',
	  autosave: 'editor-content',
	  toolbar: [  'bold','code','ul','ol','image' ]
	});
	editor.on('selectionchanged', function() {
		$(".code-popover").hide();
	});

	// 提交数据
	$("#share_code").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		
	});
	$("#user_add_note").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		$('html, body').animate({
       	    scrollTop: $("#respond").offset().top
    	}, 200);
	});

	// 提交笔记
	var commentform=$('#commentform');
	commentform.prepend('<div id="comment-status" style="display:none;" ></div>');
	var statusdiv=$('#comment-status');
	
	commentform.submit(function(e){
		e.preventDefault();
		var noteContent = editor.getValue();
		// console.log(noteContent);
		noteContent = noteContent.replace(/<pre><code>/g,"<pre>");
		noteContent = noteContent.replace(/<\/code><\/pre>/g,"</pre>");
		
		// 系列化表单数据
		var comment_parent = 0;
		var is_user_logged_in = $("#is_user_logged_in").val();
		var comment_post_ID =  20780;
		var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
		var comment = noteContent;
		var author = $("#author").val();
		var url = $("#url").val();
		var email = $("#email").val();
		if(isBlank(author) && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入昵称！</p>').show();
		} else if(isBlank(email)  && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入邮箱！</p>').show();
		} else {
			// var formdata=commentform.serialize() + "&comment=" + noteContent ;
			// 添加状态信息
			statusdiv.html('<p>Processing...</p>').show();
			// 获取表单提交地址
			var formurl=commentform.attr('action');
			
			// 异步提交
			$.ajax({
					type: 'post',
					url: formurl,
					dataType:'json',
					data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
					error: function(XMLHttpRequest, textStatus, errorThrown){
					statusdiv.html('<p class="ajax-error" >数据不完整或表单提交太快了！</p>').show();
				},
				success: function(data, textStatus){
					if(data.errorno=="0") {
						$("#submit").prop('disabled', true);
						statusdiv.html('<p class="ajax-success" >笔记已提交审核，感谢分享笔记！</p>').show();
						alert('笔记已提交审核，感谢分享笔记！');
					}else{
						statusdiv.html('<p class="ajax-error" >'+data.msg+'</p>').show();
					}
					commentform.find('textarea[name=comment]').val('');
				}
			});
			setTimeout(function(){
		        $("#submit").prop('disabled', false);
		    }, 10*1000);
		}
		return false;

	});
	$(".comt-author").click(function() {
		href = $(this).children("a").attr("href");
		if(href.indexOf("/note/")!=-1) {
			var win = window.open(href, '_blank');
  			win.focus();
		}
	});
	$(".comt-meta span").hover(function(){
		$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).children(".tooltip").removeAttr("style");
	});
	/*
	$(".wrapper i").hover(function(){
		$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
	});
	*/
	//Upvote.create('runoobvote-id', {callback: vote_callback});
	var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
	var callback = function(data) {
		//console.log($('#runoobvote-id').upvote('upvoted'));
		//console.log($('#runoobvote-id').upvote('downvoted'));
		//console.log(data);
		_vote_action = data.action;
		id_arr = data.id.split('-');
		um_id= id_arr[2];
		//console.log(um_id);
		
		var re = /^[1-9]+/;
		if (re.test(um_id)) { 
			var ajax_data = {
				_vote_action: _vote_action,
				action: "pinglun_zan",
				um_id: um_id,
				um_action: "ding"
			};
			//console.log(ajax_data);
			$.post(ajaxurl,ajax_data,function(status){
				//if(status.vote_num>999) {
				//	_voteHtml = '<span style="display: block; text-align: center;font-size: 20px; color: #6a737c; margin: 8px 0;">'+kFormatter(status.vote_num) +'</span>';
				//	$("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
				//}
				
			});
		}
	};
	if($('#comments').length && $('.upvotejs').length){
		$('.upvotejs').upvote({id: 20780, callback: callback});
	
		$.post(ajaxurl,{"action":"pinglun_zan","postid":20780},function(data){  
			$(data).each(function(key,value) {
				$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
				$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
				$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
			})
		},'json');
		
	}
	
	
});
function isBlank(str) {
    return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
	// return num;
    return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}

</script>

<link rel="stylesheet" href="../0/qa.css?1.44">
<link rel="stylesheet" type="text/css" href="../0/simditor.min.css" />
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
			<div class="article-heading-ad" id="w3cnote-ad728">
			<script async src=""></script>
			<!-- 移动版 自动调整 -->
			<ins class="adsbygoogle"
			     style="display:inline-block;min-width:300px;max-width:970px;width:100%;height:90px"
			     data-ad-client="ca-pub-5751451760833794"
			     data-ad-slot="1691338467"
			     data-ad-format="horizontal"></ins>
			<script>
			(adsbygoogle = window.adsbygoogle || []).push({});
			</script>
			</div>
			<style>
@media screen and (max-width: 768px) {
	#w3cnote-ad728 {
		display: none;
	}
}
p.note-author {
    border-bottom: 1px solid #ddd;
    font-size: 18px;
    font-weight: bold;
    color: #78a15a;
    padding-bottom: 2px;
    margin-bottom: 4px;
}
</style>
<script>
var aid = 20780;
</script>
	</div>
		
	</div>
	<div class="listcol last right-column">




<!--
	<div class="tab tab-light-blue"> 订阅</div>
	<div class="sidebar-box">
		<div class="socialicons">
			<a href="../feed" class="rss">RSS 订阅</a>
		
			<form action="//list.qq.com/cgi-bin/qf_compose_send" method="post">
			<input type="hidden" value="qf_booked_feedback" name="t">
			<input type="hidden" value="4b67b6b6c1f5e792559940cab4aebb8f1126fba880bff1a8" name="id">
			<input class="placeholder" id="feed_email" name="to" value="输入邮箱 订阅笔记" autocomplete="off">
			<input type="submit" value="订阅" class="btn btn-primary">
			</form>
		
		</div>
 
	</div>
-->	



<!--
	<div class="sidebar-box cate-list">
	<div class="sidebar-box recommend-here list-link">
			<a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;">笔记列表</a>
		</div>

 

</div>
-->

	 <div class="sidebar-box cate-list">
		 		

	 	<div class="sidebar-box recommend-here list-link">
			<a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;">教程列表</a>
		</div>
		
		<div class="cate-items"> 
				<a href="../ado">ADO 教程</a>
	<a href="../ajax">Ajax 教程</a>
	<a href="../android">Android 教程</a>
	<a href="../angularjs2">Angular2 教程</a>
	<a href="../angularjs">AngularJS 教程</a>
	<a href="../appml">AppML 教程</a>
	<a href="../asp">ASP 教程</a>
	<a href="../aspnet">ASP.NET 教程</a>
	<a href="../bootstrap">Bootstrap 教程</a>
	<a href="../bootstrap4">Bootstrap4 教程</a>
	<a href="../bootstrap5">Bootstrap5 教程</a>
	<a href="../cprogramming">C 教程</a>
	<a href="../csharp">C# 教程</a>
	<a href="../cplusplus">C++ 教程</a>
	<a href="../chartjs">Chart.js 教程</a>
	<a href="../cssref">CSS 参考手册</a>
	<a href="../css">CSS 教程</a>
	<a href="../css3">CSS3 教程</a>
	<a href="../django">Django 教程</a>
	<a href="../docker">Docker 教程</a>
	<a href="../dtd">DTD 教程</a>
	<a href="../echarts">ECharts 教程</a>
	<a href="../eclipse">Eclipse 教程</a>
	<a href="../firebug">Firebug 教程</a>
	<a href="../font-awesome">Font Awesome 图标</a>
	<a href="../foundation">Foundation 教程</a>
	<a href="../git">Git 教程</a>
	<a href="../go">Go 语言教程</a>
	<a href="../googleapi">Google 地图 API 教程</a>
	<a href="../highcharts">Highcharts 教程</a>
	<a href="../htmldom">HTML DOM 教程</a>
	<a href="../tags">HTML 参考手册</a>
	<a href="../charsets">HTML 字符集</a>
	<a href="../html">HTML 教程</a>
	<a href="../http">HTTP 教程</a>
	<a href="../ionic">ionic 教程</a>
	<a href="../ios">iOS 教程</a>
	<a href="../java">Java 教程</a>
	<a href="../jsref">JavaScript 参考手册</a>
	<a href="../js">Javascript 教程</a>
	<a href="../jeasyui">jQuery EasyUI 教程</a>
	<a href="../jquerymobile">jQuery Mobile 教程</a>
	<a href="../jqueryui">jQuery UI 教程</a>
	<a href="../jquery">jQuery 教程</a>
	<a href="../json">JSON 教程</a>
	<a href="../jsp">JSP 教程</a>
	<a href="../julia">Julia 教程</a>
	<a href="../kotlin">Kotlin 教程</a>
	<a href="../linux">Linux 教程</a>
	<a href="../lua">Lua 教程</a>
	<a href="../markdown">Markdown 教程</a>
	<a href="../matplotlib">Matplotlib 教程</a>
	<a href="../maven">Maven 教程</a>
	<a href="../memcached">Memcached 教程</a>
	<a href="../mongodb">MongoDB 教程</a>
	<a href="../mysql">MySQL 教程</a>
	<a href="../nodejs">Node.js 教程</a>
	<a href="../numpy">NumPy 教程</a>
	<a href="../pandas">Pandas 教程</a>
	<a href="../perl">Perl 教程</a>
	<a href="../php">PHP 教程</a>
	<a href="../postgresql">PostgreSQL 教程</a>
	<a href="../python3">Python 3 教程</a>
	<a href="../python">Python 基础教程</a>
	<a href="../r">R 教程</a>
	<a href="../rdf">RDF 教程</a>
	<a href="../react">React 教程</a>
	<a href="../redis">Redis 教程</a>
	<a href="../rss">RSS 教程</a>
	<a href="../ruby">Ruby 教程</a>
	<a href="../rust">Rust 教程</a>
	<a href="../sass">Sass 教程</a>
	<a href="../scala">Scala 教程</a>
	<a href="../scipy">SciPy 教程</a>
	<a href="../servlet">Servlet 教程</a>
	<a href="../soap">SOAP 教程</a>
	<a href="../sql">SQL 教程</a>
	<a href="../sqlite">SQLite 教程</a>
	<a href="../svg">SVG 教程</a>
	<a href="../svn">SVN 教程</a>
	<a href="../swift">Swift 教程</a>
	<a href="../tcpip">TCP/IP 教程</a>
	<a href="../typescript">TypeScript 教程</a>
	<a href="../vbscript">VBScript 教程</a>
	<a href="../vue2">Vue.js 教程</a>
	<a href="../vue3">Vue3 教程</a>
	<a href="../w3c">W3C 教程</a>
	<a href="../webservices">Web Service 教程</a>
	<a href="../wsdl">WSDL 教程</a>
	<a href="../xlink">XLink 教程</a>
	<a href="../dom">XML DOM 教程</a>
	<a href="../schema">XML Schema 教程</a>
	<a href="../xml">XML 教程</a>
	<a href="../xpath">XPath 教程</a>
	<a href="../xquery">XQuery 教程</a>
	<a href="../xslfo">XSLFO 教程</a>
	<a href="../xsl">XSLT 教程</a>
	<a href="../data-structures">数据结构</a>
	<a href="../regexp">正则表达式</a>
	<a href="../quiz">测验</a>
	<a href="../browsers">浏览器</a>
	<a href="../quality">网站品质</a>
	<a href="../web">网站建设指南</a>
	<a href="../hosting">网站服务器教程</a>
	<a href="../design-pattern">设计模式</a>
			
		</div> 
		 	 </div>
</div>
	</div>
</div>


<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>